package main

import (
	"context"
	"encoding/json"
	"git.900sui.cn/kc/kcgin"
	"git.900sui.cn/kc/kcgin/logs"
	"git.900sui.cn/kc/rabbitmq"
	reservation2 "git.900sui.cn/kc/rpcinterface/interface/elastic/reservation"
	"git.900sui.cn/kc/rpcinterface/interface/task/reservation"

	reservationElastic "git.900sui.cn/kc/rpcinterface/client/elastic/reservation"
	"github.com/streadway/amqp"
)

// 预约
func main() {
	logs.Info("Environment Variable:MSF_ENV:", kcgin.KcConfig.RunMode)
	err := rabbitmq.Rabbitmq.Consume(kcgin.AppConfig.String("queue.setReservationInfo"), func(msg amqp.Delivery) {
		var date reservation.ArgsReservationAdd
		if err := json.Unmarshal(msg.Body, &date); err != nil {
			return
		}
		// 预约rpc es
		rpcReservationEs := new(reservationElastic.Reservation).Init()
		defer rpcReservationEs.Close()
		var reply bool
		if err := rpcReservationEs.SetReservationInfo(context.Background(), &reservation2.ArgsSetReservationInfo{Id: date.ReservationID}, &reply); err != nil {
			logs.Error("rpcReservationEs.SetReservationInfo error:%s\n",err.Error())
			return
		}
		return
	})
	if err != nil {
		panic(err.Error())
	}
}
